package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/*
删除表中伍六七的记录
 */
public class JDBCUtil_4 {
    public static void main(String[] args) {
        Connection conn=null;
        Statement stmt=null;

        //建立链接
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            //创建connection对象链接
             conn = DriverManager.getConnection("jdbc:mysql:///sanqiansql?serverTimezone=GMT", "root", "shaozhaoming");

            String sql ="delete from demo where id=6";

             stmt = conn.createStatement();

             int count = stmt.executeUpdate(sql);
            System.out.println(count);
             if(count >0){
                 System.out.println("删除成功");
             }else{
                 System.out.println("删除失败");
             }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            if(stmt!=null){
                try {
                    stmt.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if(conn!=null){
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
